/*
 * Dicionario.java
 * 
 * Created on 26/Nov/2007, 23:55:58
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Dicionario;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;

/**
 *
 * @author Pedro
 */
public class Dicionario implements IDicionario {

    Hashtable<Integer, String> dicionario = new Hashtable<Integer, String>();

    public void addId(ArrayList t) {


        //HashMap<Integer, String> dicionario = new HashMap<Integer, String>();
        // StringTokenizer st = new StringTokenizer("this is a testIf the internal array of our hash map consisted of only one element, then all the entries would have to go into that one array location, as one long linked list. That is pretty inefficient, our updates and accesses would consist of linear searches through a linked list, which is much slower than if each array index in the map contained just one object. The time to access or update the linked list is linearly dependent on the size of the list, whereas using a hash function to access or update a single element in an array is independent of the size of the array — in terms of the asymptotic performance (Big-O notation), the former is O(n), whereas the latter is O(1). So it makes sense to use a bigger array rather than let too many entries accumulate in too few array locations.");
        ArrayList<String> palavras = new ArrayList<String>();

        String pal = new String();


        Iterator it = t.iterator();
        while (it.hasNext()) {
            StringTokenizer st = new StringTokenizer(it.next().toString());
            while (st.hasMoreTokens()) {
                pal = st.nextToken();
                dicionario.put(pal.hashCode(), pal);
                System.out.println(dicionario.get(pal.hashCode()));
                int hash = 0;
                if (hash == pal.hashCode()) {
                    hash = pal.hashCode();
                }
                System.out.println(hash);
            }

            //  it.next();
        }
    }

    public int getID(String a) {

        try {
                
            if (dicionario.get(a.hashCode()).equals(a)) {
                return a.hashCode();
            }
        } catch (NullPointerException nullPointerException) {
            return -1;
        }

        return -1;
    }

    public void addId(String s) {

        String pal = new String();

        StringTokenizer st = new StringTokenizer(s);

        while (st.hasMoreTokens()) {
            pal = st.nextToken();
            dicionario.put(pal.hashCode(), pal);
            // System.out.println(dicionario.get(pal.hashCode()));
        }
    }
    
    public String getPalavra(int i)
    {
    
    
     return dicionario.get(i);   
    
    }
}